/**
 * 
 */
package com.zte.claa.inficombo.csa.app.service.custparam.listener;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.connection.Message;
import org.springframework.data.redis.connection.MessageListener;
import org.springframework.data.redis.core.StringRedisTemplate;

import com.zte.claa.inficombo.csa.app.service.custparam.LocCustParamModelService;
import com.zte.claa.inficombo.csa.app.service.message.MessageSubscriber;

/**
 * @author hxl
 *
 */
@MessageSubscriber(topic = "t_web_loc_cust_param")
public class LocCustParamChangeListener implements MessageListener {

	@Autowired
	private StringRedisTemplate redisTemplate;
	
	@Autowired
	private LocCustParamModelService locCustParamModelService;
		
	private Logger logger = LoggerFactory.getLogger(this.getClass().getName());

	
	//接收到web发送过来的CUD消息,忽略消息具体内容,重新加载map
	@Override
	public void onMessage(Message message, byte[] pattern) {
		logger.info("receive web location custom param change: {}", message);
		try {			
			String body = (String)redisTemplate.getValueSerializer().deserialize(message.getBody());		
			if(body != null && body.length() != 0){	
				
				locCustParamModelService.reloadLocCustParam();	
			}			
		} catch (Exception e) {
			logger.error(e.getMessage(), e);
		}
	}

}
